package com.changgou.goods.dao;

import com.changgou.goods.pojo.Brand;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@Repository //用于将数据访问层 (DAO 层 ) 的类标识为 Spring Bean
public interface BrandMapper extends Mapper<Brand> {

    //自定义方法1，根据分类名称查询品牌列表
    @Select("SELECT b.name,b.image FROM tb_brand b,tb_category_brand cb,tb_category c WHERE b.id = cb.brand_id AND c.id=cb.category_id AND c.name=#{name}")
    List<Map> findListByCategoryName(@Param("name") String categoryName);

    @Select("SELECT DISTINCT s.name,s.options FROM tb_spec s,tb_category c WHERE s.template_id = c.template_id AND c.name=#{categoryName} ")
    //自定义方法2，根据商品分类名称查询规格
    List<Map> findSpecListByCategoryName(@Param("categoryName") String categoryName);
}
